/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-17 15:33:27
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-18 17:32:54
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/controller/broadcast_controller.dart';
import 'package:get/get.dart';
import 'package:line_icons/line_icons.dart';

class BroadcastMenu extends StatelessWidget {
  const BroadcastMenu({Key key, this.currentIndex, this.onChange, this.addTap})
      : super(key: key);
  final int currentIndex;
  final ValueChanged<int> onChange;
  final VoidCallback addTap;

  @override
  Widget build(BuildContext context) => GetBuilder<BroadcaseController>(
        builder: (_controller) => Row(
          children: [
            Container(
              height: 50,
              width: MediaQuery.of(context).size.width * 0.6,
              child: ListView.builder(
                scrollDirection: Axis.horizontal,
                itemCount: _controller.menus.length,
                itemBuilder: (context, index) => GestureDetector(
                  onTap: () => onChange(index),
                  child: Padding(
                    padding: const EdgeInsets.symmetric(
                      horizontal: 10,
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text("${_controller.menus[index].value}",
                            style: TextStyle(
                              fontSize: index == currentIndex ? 18 : 13,
                              fontWeight: index == currentIndex
                                  ? FontWeight.w700
                                  : FontWeight.w500,
                            )),
                        if (currentIndex == index)
                          Container(
                            width: 24,
                            height: 4,
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(20),
                              color: Colors.black,
                            ),
                          ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Spacer(),
            IconButton(
              icon: Icon(LineIcons.plus),
              onPressed: () => addTap(),
            ),
          ],
        ),
      );
}
